<?php
namespace app\admin\controller;
use app\common\model\ManagerGongzi;
use app\common\model\ManagerGongziKouchu;
use app\common\model\ManagerGongziZhaoxin;
use app\common\model\Kaoqin;
use app\common\model\Xueyuan;

class Gongzi extends Base
{
    public function __construct () {
        parent::__construct();
    }
    /*
         列表
         */
    public function list(){
        $input = input('get.');
        $where = [];
        $page = max(input('page'),1);
        $size = input('limit',20);

        if($input['mid']){
            $where['mid'] = $input['mid'];
        }
        if($input['time']){
            $where['time'] = $input['time'];
        }
        $gongziList = ManagerGongzi::getPage($where,$page,$size);
        foreach($gongziList as $key => $gongzi){
            //招新
            $zx_w = array(
                'time'  => $gongzi['time'],
                'mid'   => $gongzi['mid']
            );

            $gongziList[$key]['zhaoxin'] = ManagerGongziZhaoxin::getCount($zx_w,'id') * config('zhaoxin_gongzi');

            //课时费
            $ks_w = array(
                'time'  => array('like',$gongzi['time'].'%'),
                'manager_name'=>array('eq',$gongzi['name']),
            );
            $gongzi[$key]['keshi'] = Kaoqin::getSum($ks_w,'num') * config('keshi_gongzi');

            //扣除工资
            $w = array(
                'mgid' => $gongzi['id'],
                'time' => array('like',$gongzi['time'].'%')
            );
            $gongziList[$key]['kouchu']= ManagerGongziKouchu::getSum($w,'money');
        }
        $total = ManagerGongzi::getCount($where);
        if(!$gongziList) {
            return returnJson(1,'');
        }
        return returnJson(0,'',[
            'list' => $gongziList,
            'size' => $size,
            'total' => $total
        ]);
    }

    /**
     * 招新列表
     * @return void
     */
    public function zhaoxin()
    {
        //查询条件
        $where['id'] = input('gid');

        $page = max(input('page'),1);
        $size = input('limit',10);

        //工资信息
        $gongzi = ManagerGongzi::getOne($where);

        if($gongzi) {
            $zx_w = array(
                'time'  => array('eq',$gongzi['time']),
                'mid'   => $gongzi['mid'],
            );



            //获取分页列表
            $list = ManagerGongziZhaoxin::getPage($zx_w,$page,$size);
            $total = ManagerGongziZhaoxin::getCount($zx_w);

            if(!$list){
                $list=[];
            }else{
                $xy_w = array(
                    'id'=>array('in',array_column($list,'sid')),
                );
                $xueyuan = Xueyuan::getColumn($xy_w,'id,name');
                foreach($list as $k=>$v){
                    $list[$k]['xueyuan'] = isset($xueyuan[$v['sid']])?$xueyuan[$v['sid']]:'';
                }
            }
            //返回信息
            return returnJson(0,'',[
                'list' => $list,
                'size' => $size,
                'total' => $total
            ]);
        }
        //返回信息
        return returnJson(0,'',[
            'list' => [],
            'size' => $size,
            'total' => 0
        ]);
    }

}
